//引入请求的工具
import ajax from "@/utils/request.js";

//获取全部频道列表的接口
const article = obj => {
  return ajax({
    url: "/app/v1_1/articles",
    method: "GET",
    params: {
      channel_id: obj.channel_id,
      timestamp: obj.timestamp,
      with_top: 1 //包含置顶
    }
  });
};

//对文章不喜欢的接口
const disLike = id => {
  return ajax({
    url: "/app/v1_0/article/dislikes",
    method: "POST",
    data: {
      target: id
    }
  });
};

//举报文章的接口
const reportArticle = obj => {
  const { target, type } = obj;
  return ajax({
    url: "/app/v1_0/article/reports",
    method: "POST",
    data: { target, type }
  });
};

//文章详情  val 文章的id
const detail = val => {
  return ajax({
    url: `/app/v1_0/articles/${val}`,
    method: "GET"
  });
};

//对文章进行点赞的接口
const addLike = artId => {
  return ajax({
    url: "/app/v1_0/article/likings",
    method: "POST",
    data: {
      target: artId
    }
  });
};

//取消对文章点赞的接口
const delLike = artId => {
  return ajax({
    url: `/app/v1_0/article/likings/${artId}`,
    method: "DELETE"
  });
};

//不喜欢文章的接口
const addDisLike = artId => {
  return ajax({
    url: "/app/v1_0/article/dislikes",
    method: "POST",
    data: {
      target: artId
    }
  });
};

//取消不喜欢文章的接口
const deleteDisLike = artId => {
  return ajax({
    url: `/app/v1_0/article/dislikes/${artId}`,
    method: "DELETE"
  });
};

//导出接口
export {
  article,
  disLike,
  reportArticle,
  detail,
  addLike,
  delLike,
  addDisLike,
  deleteDisLike
};
